<script type="text/javascript">
    if (getCookie("username") != null) {
        $("j_username").value = getCookie("username");
        $("j_password").focus();
    } else {
        $("j_username").focus();
    }
    
    function saveUsername(theForm) {
		var expires = new Date();
		expires.setTime(expires.getTime() + 24 * 30 * 60 * 60 * 1000); // sets it for approx 30 days.
		setCookie("username",theForm.j_username.value,expires,"<c:url value="/"/>");    		
    }
    
    function validateForm(form) {
    	if(validateRequired(form)){
        	var patchca = $.trim($("#patchca").val());
        	// 判断验证码不为空
        	if(isUndefined(patchca) || patchca == null || "" == patchca){
        		alert("\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801\u3002");
        		return false;
        	}
        	// 判断验证码是否正确
        	if(patchca == getCookie("captcha")){
        		$("#j_password").val($("#j_username").val() + $("#j_password").val());
        		return true;
        	}else{
        		alert("\u9a8c\u8bc1\u7801\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\u3002");
        		return false;
        	}
    	}
        return false; 
    } 
    
    function passwordHint() {
        if ($("j_username").value.length == 0) {
            alert("<s:text name="errors.requiredField"><s:param><s:text name="label.username"/></s:param></s:text>");
            $("j_username").focus();
        } else {
            location.href="<c:url value="/passwordHint"/>?username=" + $("j_username").value;
        }
    }
    
    function required () { 
        this.aa = new Array("j_username", "<s:text name="errors.requiredField"><s:param><s:text name="label.username"/></s:param></s:text>", new Function ("varName", " return this[varName];"));
        this.ab = new Array("j_password", "<s:text name="errors.requiredField"><s:param><s:text name="label.password"/></s:param></s:text>", new Function ("varName", " return this[varName];"));
    } 
</script>
